import express from "express";
import fetch from "node-fetch";

const app = express();

app.get("/fred", async (req, res) => {
  const { id, apiKey } = req.query;
  const url = `https://api.stlouisfed.org/fred/series/observations?series_id=${id}&api_key=${apiKey}&file_type=json`;

  try {
    const response = await fetch(url);
    const data = await response.json();
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.json(data);
  } catch (err) {
    res.status(500).json({ error: err.message });
  }
});

app.listen(3000, () => console.log("✅ 本地代理运行在 http://127.0.0.1:3000/fred?id=RRPONTSYD&apiKey=104a9649064ecc8fc6dc4b83f75a1c2f"));
